package com.dkm.orproject.dkmoa.service.serviceimpl;

import com.dkm.orproject.dkmoa.dao.OaOfficeSuppliesMapper;
import com.dkm.orproject.dkmoa.domain.OaOfficeSupplies;
import com.dkm.orproject.dkmoa.service.OaOfficeSuppliesService;
import com.dkm.orproject.utils.utils.IdToobtainUtils;
import com.dkm.orproject.utils.utils.Tools;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 *  @ClassName : OaOfficeSuppliesServiceImpl  //类名
 *  @Description : 办公用品  //描述
 *  @Author : 石智诚  //作者
 *  @Date: 2020-11-11 16:53  //时间
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class OaOfficeSuppliesServiceImpl implements OaOfficeSuppliesService {
    /**
     * 办公用品mapper
     */
    @Resource
    OaOfficeSuppliesMapper officeSuppliesMapper;
    /**
     * 雪花算法
     */
    @Resource
    IdToobtainUtils utils;
    /**
     * 根据id删除
     * @param pkOfficeSuppliesId 办公用品id
     * @return 回调函数
     */
    @Override
    public int deleteById(Long pkOfficeSuppliesId) {
        return officeSuppliesMapper.deleteByPrimaryKey(pkOfficeSuppliesId);
    }

    /**
     * 增加
     * @param record 办公用品模型
     * @return 回调函数
     */
    @Override
    public int insert(OaOfficeSupplies record) {
        record.setOfficeSuppliesCode(Tools.clientIdentity(String.valueOf(officeSuppliesMapper.count()),"os",4));
        record.setPkOfficeSuppliesId(utils.getNumberId());
        record.setIsRevision("1");
        return officeSuppliesMapper.insertSelective(record);
    }

    /**
     * 根据id查询
     * @param pkOfficeSuppliesId 办公用品id
     * @return 办公用品模型
     */
    @Override
    public OaOfficeSupplies selectById(Long pkOfficeSuppliesId) {
        return officeSuppliesMapper.selectByPrimaryKey(pkOfficeSuppliesId);
    }

    /**
     * 根据id查询
     * @param record 办公用品模型
     * @return 回调函数
     */
    @Override
    public int updateById(OaOfficeSupplies record) {
        return officeSuppliesMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public List<OaOfficeSupplies> findAll(OaOfficeSupplies oaOfficeSupplies, Integer page, Integer limit, String startDate, String endDate) {
        PageHelper.startPage(page,limit);
        return officeSuppliesMapper.findAll(oaOfficeSupplies,startDate,endDate);
    }

    @Override
    public Long countAll(OaOfficeSupplies oaOfficeSupplies,  String startDate, String endDate) {
        return officeSuppliesMapper.countAll(oaOfficeSupplies,startDate,endDate);
    }

    @Override
    public int deleteAll(List<Long> ids) {
        return officeSuppliesMapper.deleteAll(ids);
    }

    @Override
    public List<OaOfficeSupplies> findByAll(List<Long> ids) {
        return officeSuppliesMapper.findByAll(ids);
    }

    @Override
    public int count() {
        return 0;
    }
}
